/*
 * Copyright Aristool AG Switzerland
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); 
 * you may not use this file except in compliance with the License. 
 * You may obtain a copy of the License at 
 * 
 * http://www.apache.org/licenses/LICENSE-2.0 
 * 
 * Unless required by applicable law or agreed to in writing, software 
 * distributed under the License is distributed on an "AS IS" BASIS, 
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
 * See the License for the specific language governing permissions and 
 * limitations under the License.
 */
package org.opprua.tidy.conversion;

import java.math.BigDecimal;
import java.math.BigInteger;
import java.sql.Time;
import java.sql.Timestamp;
import java.util.Date;

import org.opprua.tidy.util.TimePoint;

/**
 * TODO: add Java doc
 * 
 * Prepared for first commit: 15.07.2007
 * 
 * @author Lin Li
 */
class CTString extends ChangeType<String> {

  private SingleChanger<String>[] changers = null;

  private static class MyString extends SingleChanger<String> {

    public MyString(Class<?> c) {
      super(c);
    }

    public String change(Object data) {
      return String.valueOf(data);
    }
  }

  public CTString() {
    super(String.class, "");
  }

  @Override
  @SuppressWarnings("unchecked")
  public SingleChanger<String>[] getchangers() {
    if (changers == null) {
      changers = new MyString[] {
                  new MyString(Boolean.class),

                  new MyString(Character.class), new MyString(Byte.class),
                  new MyString(Double.class), new MyString(Float.class),
                  new MyString(Integer.class), new MyString(Long.class), new MyString(Short.class),
                  new MyString(BigDecimal.class), new MyString(BigInteger.class),

                  new MyString(Date.class) {

                    public String change(Object data) {
                      return TimePoint.from(data).source(TimePoint.EUROPEAN_DATE);
                    }
                  }, new MyString(java.sql.Date.class) {

                    public String change(Object data) {
                      return TimePoint.from(data).source(TimePoint.DATABASE_DATE);
                    }
                  }, new MyString(Time.class) {

                    public String change(Object data) {
                      return TimePoint.from(data).source(TimePoint.DATABASE_TIME);
                    }
                  }, new MyString(Timestamp.class) {

                    public String change(Object data) {
                      return TimePoint.from(data).source(TimePoint.DATABASE_TIMESTAMP);
                    }
                  } };
    }
    return changers;
  }
}